package com.bdc.util;

import java.util.HashMap;
import java.util.Map;
import java.util.ResourceBundle;

public class ResourceUtil {
	
	private ResourceUtil() {}
	
	private static Map<String, ResourceBundle> resources = new HashMap<String, ResourceBundle>();
	
	public static String getVal(String propertiesFileName, String key) {
		if(propertiesFileName == null || key == null) {
			throw new IllegalArgumentException("The propertiesFileName or key is null");
		}
		
		String val = key;
		ResourceBundle bundle = resources.get(propertiesFileName);
		String i18nVal = null;
		if(bundle != null) {
			i18nVal = bundle.getString(key);
		} else {
			bundle = ResourceBundle.getBundle(propertiesFileName);
			resources.put(propertiesFileName, bundle);
			i18nVal = bundle.getString(key);
		}
		
		if(i18nVal != null) {
			val = i18nVal;
		}
		return val;
	}
	
	public static String getLabelVal(String key) {
		String val = getVal("label", key);
		if(val == null) {
			val = key;
		}
		
		return val;
	}
}
